<style>input{text-align: center;}</style>
<div>
    <div class="col-lg-12">
        <section class="panel">
            <div class="panel-body">
                <form class="form-horizontal adminex-form" onsubmit="return false;">
                    <div style="width: 85%;">
                        <section class="panel">
                            <header class="panel-heading custom-tab blue-tab">
                                <ul class="nav nav-tabs">
                                    <li class="active">
                                        <a href="#rebates" data-toggle="tab">联创团队业绩返点设置</a>
                                    </li>
                                    <li class="">
                                        <a href="#other_rebates" data-toggle="tab">其他团队业绩返点设置</a>
                                    </li>
                                    <li class="">
                                        <a href="#bonus" data-toggle="tab">一次性推荐奖设置</a>
                                    </li>
                                    <!--<li class="">
                                        <a href="#charge" data-toggle="tab">运费设置</a>
                                    </li>-->
                                </ul>
                            </header>
                            <div class="panel-body">
                                <div class="tab-content">
                                    <div class="tab-pane active" id="rebates" style="float: left;width: 50%;">
                                        <table id="unite-table">
                                            <tr>
                                                <td style="background-color: gainsboro;">销售额开始区间（万）</td>
                                                <td style="background-color: gainsboro;">销售额结束区间（万）</td>
                                                <td style="background-color: gainsboro;">返点率（%）</td>
                                                <td style="background-color: gainsboro;">操作</td>
                                            </tr>
                                            <?php if(!empty($this->rebaseList)){?>
                                                <?php foreach ($this->rebaseList as $k=>$v){?>
                                                    <tr>
                                                        <td>
                                                            <input type="text" class="form-control" value="<?php echo $v['start_sale_price']?>" id="start_sale<?php echo $v['id'];?>" placeholder="请输入销售额开始区间">
                                                        </td>
                                                        <td>
                                                            <input type="text" class="form-control" value="<?php echo $v['end_sale_price']?>" id="end_sale<?php echo $v['id'];?>" placeholder="请输入销售额结束区间">
                                                        </td>
                                                        <td>
                                                            <input type="text" class="form-control" value="<?php echo $v['rebate_rate'] *100;?>" id="rebate_rate<?php echo $v['id'];?>" placeholder="请输入返点率">
                                                        </td>
                                                        <td>
                                                            <button class="btn btn-default" type="button"  data-toggle="modal" onclick="save_bonus(<?php echo $v['id']?>);">保存</button>
                                                        </td>
                                                    </tr>
                                                <?php }?>
                                            <?php }?>
                                        </table>
                                        <div style="text-align: left;margin-left: 8%;margin-top: 1%;" id="unite-flag" type="unite">
                                            <img  src="/images/add.png" alt="" style="width: 25px;height: 25px;cursor: pointer;" onclick="add(0,'unite');"/>
                                        </div>
                                    </div>

                                    <div class="tab-pane" id="other_rebates" style="float: left;width: 50%;">
                                        <table id="other-table">
                                            <tr>
                                                <td style="background-color: gainsboro;">销售额开始区间（万）</td>
                                                <td style="background-color: gainsboro;">销售额结束区间（万）</td>
                                                <td style="background-color: gainsboro;">返点率（%）</td>
                                                <td style="background-color: gainsboro;">操作</td>
                                            </tr>
                                            <?php if(!empty($this->otherRebaseList)){?>
                                                <?php foreach ($this->otherRebaseList as $k=>$v){?>
                                                    <tr>
                                                        <td>
                                                            <input type="text" class="form-control" value="<?php echo $v['start_sale_price']?>" id="start_sale<?php echo $v['id'];?>" placeholder="请输入销售额开始区间">
                                                        </td>
                                                        <td>
                                                            <input type="text" class="form-control" value="<?php echo $v['end_sale_price']?>" id="end_sale<?php echo $v['id'];?>" placeholder="请输入销售额结束区间">
                                                        </td>
                                                        <td>
                                                            <input type="text" class="form-control" value="<?php echo $v['rebate_rate'] *100;?>" id="rebate_rate<?php echo $v['id'];?>" placeholder="请输入返点率">
                                                        </td>
                                                        <td>
                                                            <button class="btn btn-default" type="button"  data-toggle="modal" onclick="save_bonus(<?php echo $v['id']?>);">保存</button>
                                                        </td>
                                                    </tr>
                                                <?php }?>
                                            <?php }?>
                                        </table>
                                        <div style="text-align: left;margin-left: 8%;margin-top: 1%;" id="other-flag">
                                            <img src="/images/add.png" alt="" style="width: 25px;height: 25px;cursor: pointer;" onclick="add(0,'other');"/>
                                        </div>
                                    </div>

                                    <div class="tab-pane" id="bonus" style="float: left;width: 30%;">
                                        <table>
                                            <tr>
                                                <td style="background-color: gainsboro;">类别</td>
                                                <td style="background-color: gainsboro;">一次性推荐奖（元）</td>
                                                <td style="background-color: gainsboro;">操作</td>
                                            </tr>
                                            <?php if(!empty($this->recommendList)){?>
                                                <?php foreach ($this->recommendList as $k=>$v){?>
                                                    <tr>
                                                        <td>
                                                            <lable class="control-label"><?php echo $v['name']?></lable>
                                                        </td>
                                                        <td>
                                                            <input type="text" class="form-control" value="<?php echo $v['administrate_price']?>" id="price<?php echo $v['id'];?>" placeholder="请输入管理奖金">
                                                        </td>
                                                        <td>
                                                            <button class="btn btn-default" type="button"  data-toggle="modal" onclick="edit(<?php echo $v['id']?>);">保存</button>
                                                        </td>
                                                    </tr>
                                                <?php }?>
                                            <?php }?>
                                        </table>
                                    </div>
                                    <div class="tab-pane" id="charge" style="float: left;width: 50%;">
                                        <div style="clear: both"></div>
                                        <div style="margin-top: 20px;"></div>

                                        <div class="form-group">
                                            <div class="modal-footer" style="text-align: left;margin-left: 6%;">
                                                <button class="btn btn-success" type="button" href="#"
                                                        style="background-color:#e9552e;border-color:#e9552e;">保存
                                                </button>
                                                <button class="btn btn-success" type="button"
                                                        style="background-color:#CCCCCC;border-color:#CCCCCC;" data-dismiss="modal"
                                                        aria-hidden="true">
                                                    <a href="#" onclick="window.history.go(-1)" style="text-decoration: none;">取消</a></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </form>
            </div>

        </section>
    </div>
</div>
<script type="text/javascript">

    /**
     * rebate_type  区分是 联创  还是 非联创
     */
    function save_bonus(e,m,rebate_type) {
        var id = e;
        if(id >0){//编辑返点率(update)
            var start_sale_price = $('#start_sale'+e).val();
            var end_sale_price = $('#end_sale'+e).val();
            var rebate_rate = $('#rebate_rate'+e).val();
            layer.confirm('确定要更改该区间业绩返点？', function(index){
                $.ajax({
                    type:'get',
                    url : '/setting/system',
                    data :{
                        'id':id,
                        'start_sale_price':start_sale_price,
                        'end_sale_price':end_sale_price,
                        'rebate_rate':rebate_rate,
                        'type':'rebates'
                    },
                    dataType:'json',
                    success:function(msg){
                        if (msg.code == 200) {
                            layer.close(index);
                            layer.alert('保存成功',function () {
                                location.href = '/setting/system';
                            })
                        } else{
                            layer.close(index);
                            layer.alert(msg.message);
                        }
                    }
                });
            });
        }else{//新增返点率配置(insert)
            var start= $('#start'+m).val();
            var end= $('#end'+m).val();
            var rebate= $('#rebate'+m).val();
            layer.confirm('确定要新增区间业绩返点？', function(index){
                $.ajax({
                    type:'get',
                    url : '/setting/system',
                    data :{
                        'start_sale_price':start,
                        'end_sale_price':end,
                        'rebate_rate':rebate,
                        'rebate_type':rebate_type,
                        'type':'rebates'
                    },
                    dataType:'json',
                    success:function(msg){
                        if (msg.code == 200) {
                            layer.close(index);
                            layer.alert('新增成功',function () {
                                location.href = '/setting/system';
                            })
                        } else{
                            layer.close(index);
                            layer.alert(msg.message);
                        }
                    }
                });
            });
        }
    }

    /**
     * 编辑价格区间
     * @param e
     */
    function edit(e) {
        var id = e;
        var price = $('#price'+e).val();
        layer.confirm('确定要更改该类别管理奖金？', function(index){
            $.ajax({
                type:'get',
                url : '/setting/system',
                data :{'id':id,'administrate_price':price,'type':'bonus'},
                dataType:'json',
                success:function(msg){
                    if (msg.code == 200) {
                        layer.close(index);
                        layer.alert('保存成功',function () {
                            location.href = '/setting/system';
                        })
                    } else{
                        layer.close(index);
                        layer.alert(msg.message);
                    }
                }
            });
        });
    }

    function add(num,type) {
        var e =  num;
        var tr_content = [];
        tr_content.push('<tr>');
        tr_content.push('<td>');
        tr_content.push('<input type="text" class="form-control" id="start'+e+'" placeholder="请输入销售额开始区间">');
        tr_content.push('</td>');
        tr_content.push('<td>');
        tr_content.push('<input type="text" class="form-control" id="end'+e+'" placeholder="请输入销售额结束区间">');
        tr_content.push('</td>');
        tr_content.push('<td><input type="text" class="form-control" id="rebate'+e+'" placeholder="请输入返点率"></td>');
        tr_content.push('</td>');
        tr_content.push('<td><button class="btn btn-default" type="button"  data-toggle="modal" onclick="save_bonus(0,'+e+',\''+type+'\')">保存</button></td>');
        tr_content.push('</tr>');
        $("#"+type+"-table").append(tr_content.join(''));
        e++;
        var img = '<img  type="'+type+'" src="/images/add.png" alt="" style="width: 25px;height: 25px;cursor: pointer;" onclick="add('+e+',\''+type+'\');"/>';
        $("#"+type+"-flag").html('').html(img);
    }
</script>